from strategy_mode import dataLoader, str_cal, Trading, TradingRules

# 上涨模式
def UpMode(
    df_day, df_day_1, preTYPES, mode, tradePersent, day_lists, day, statsdic, count_in
):

    return mode, tradePersent


# 下跌模式
def DownMode(
    df_day, df_day_1, preTYPES, mode, tradePersent, day_lists, day, statsdic, count_in
):

    return mode, tradePersent


def RoundMode(
    df_day, df_day_1, preTYPES, mode, tradePersent, day_lists, day, statsdic, count_in
):

    return mode, tradePersent


def Main(
    df_day,
    df_day_1,
    mode="BUY/SELL",
    line_Pares=5,
    tradePersent=1,
    day_lists=[],
    day=0,
    statsdic={},
    count_in=1,
):

    types = statsdic["TYPES"]
    tradePersent = 0

    # TODO 增加循环判断节,解决连续下跌止损问题
    for col in df_day.index.tolist():
        if "All_by%_sum" in col:
            if "rolling" not in col:
                sum_All = col
            elif "TH_" in col:
                sum_up = col
            elif "TL_" in col:
                sum_down = col
            elif "T" in col:
                sum_rolling = col
            else:
                sum_ro = col
        elif "All_sort" in col:
            if "rolling" not in col:
                sort_All = col
            elif "TH_" in col:
                sort_up = col
            elif "TL_" in col:
                sort_down = col
            elif "T" in col:
                sort_rolling = col
            else:
                sort_ro = col

    # print(
    #     " sum_rolling {},\n sum_up {},\n sum_down {},\n sum_All {} \n".format(
    #         sum_rolling, sum_up, sum_down, sum_All
    #     )
    # )
    if df_day[sum_All] < df_day_1[sum_All] * 1:
        types = "LOW"

    elif df_day[sum_All] > df_day_1[sum_All] * 1:  # 上涨模式
        types = "HIGH"
    else:
        types = "ROUND"
    # TODO
    # if (
    #     df_day_1[sum_All] > df_day_1[sum_down] and df_day[sum_All] < df_day[sum_down]
    # ) or (df_day_1[sum_All] < df_day_1[sum_up] and df_day[sum_All] > df_day[sum_up]):
    #     if df_day["All_sort"] >= 0 and df_day["Avg_ma_144"] > df_day_1["Avg_ma_144"]:
    #         mode = "SELL"
    #         tradePersent = 1

    #     elif df_day["All_sort"] <= 0 and df_day["Avg_ma_144"] < df_day_1["Avg_ma_144"]:
    #         mode = "BUY"
    #         tradePersent = 1

    if (
        df_day_1[sum_All] > df_day_1[sum_down]
        and df_day[sum_All] < df_day[sum_down]
        and df_day["All_sort"] >= 0
        # and df_day["Avg_ma_144"] > df_day_1["Avg_ma_144"]
    ):
        mode = "SELL"
        tradePersent = 1

    elif (
        df_day_1[sum_All] < df_day_1[sum_up]
        and df_day[sum_All] > df_day[sum_up]
        and df_day["All_sort"] <= 0
        # and df_day["Avg_ma_144"] < df_day_1["Avg_ma_144"]
    ):
        mode = "BUY"
        tradePersent = 1

    # statsdic["TYPES"] = types
    return mode, tradePersent, statsdic
